#include "user_config.h"
#include "user_event.h"
#include "user_gpio.h"
#include "user_player.h"
#include "user_pwm.h"
#include "user_timer.h"
#include "user_uart.h"

#define TAG "auto_gpio"

#define UART_SEND_MAX      16

typedef struct {
  char  data[UART_SEND_MAX];
  int   len;
}uart_data_t;

const uart_data_t g_uart_buf[] = {
  {{0x4F, 0x00, 0x01}, 3}, //text1
  {{0x4F, 0x00, 0x02}, 3}, //text2
  {{0x4F, 0x00, 0x03}, 3}, //text3
  {{0x4F, 0x00, 0x04}, 3}, //text4
  {{0x4F, 0x00, 0x05}, 3}, //text5
  {{0x4F, 0x00, 0x06}, 3}, //text6
  {{0x4F, 0x00, 0x07}, 3}, //text7
  {{0x4F, 0x00, 0x08}, 3}, //text8
  {{0x4F, 0x00, 0x09}, 3}, //text9
  {{0x4F, 0x00, 0x0A}, 3}, //text10
  {{0x4F, 0x00, 0x0B}, 3}, //text11
  {{0x5F, 0x00, 0x0F}, 3}, //text12
  {{0x5F, 0x00, 0x10}, 3}, //text13
  {{0x5F, 0x00, 0x11}, 3}, //text14
  {{0x5F, 0x00, 0x12}, 3}, //text15
  {{0x5F, 0x00, 0x13}, 3}, //text16
  {{0x5F, 0x00, 0x14}, 3}, //text17
  {{0x5F, 0x00, 0x15}, 3}, //text18
  {{0x5F, 0x00, 0x16}, 3}, //text19
  {{0x5F, 0x00, 0x17}, 3}, //text20
  {{0x5F, 0x00, 0x18}, 3}, //text21
  {{0x5F, 0x00, 0x19}, 3}, //text22
  {{0x5F, 0x00, 0x1A}, 3}, //text23
  {{0x5F, 0x00, 0x1B}, 3}, //text24
  {{0x5F, 0x00, 0x1C}, 3}, //text25
  {{0x5F, 0x00, 0x1D}, 3}, //text26
  {{0x5F, 0x00, 0x1E}, 3}, //text27
  {{0x5F, 0x00, 0x1F}, 3}, //text28
  {{0x5F, 0x00, 0x20}, 3}, //text29
  {{0x5F, 0x00, 0x21}, 3}, //text30
  {{0x5F, 0x00, 0x22}, 3}, //text31
  {{0x5F, 0x00, 0x23}, 3}, //text32
  {{0x5F, 0x00, 0x24}, 3}, //text33
  {{0x5F, 0x00, 0x25}, 3}, //text34
  {{0x5F, 0x00, 0x26}, 3}, //text35
  {{0x5F, 0x00, 0x27}, 3}, //text36
  {{0x5F, 0x00, 0x28}, 3}, //text37
  {{0x5F, 0x00, 0x29}, 3}, //text38
  {{0x5F, 0x00, 0x2A}, 3}, //text39
  {{0x5F, 0x00, 0x2B}, 3}, //text40
  {{0x5F, 0x00, 0x2C}, 3}, //text41
  {{0x5F, 0x00, 0x2D}, 3}, //text42
  {{0x5F, 0x00, 0x2E}, 3}, //text43
  {{0x5F, 0x00, 0x2F}, 3}, //text44
  {{0x5F, 0x00, 0x30}, 3}, //text45
  {{0x5F, 0x00, 0x31}, 3}, //text46
  {{0x5F, 0x00, 0x32}, 3}, //text47
  {{0x5F, 0x00, 0x33}, 3}, //text48
  {{0x5F, 0x00, 0x34}, 3}, //text49
  {{0x5F, 0x00, 0x35}, 3}, //text50
  {{0x5F, 0x00, 0x36}, 3}, //text51
  {{0x5F, 0x00, 0x37}, 3}, //text52
  {{0x5F, 0x00, 0x38}, 3}, //text53
  {{0x5F, 0x00, 0x39}, 3}, //text54
  {{0x5F, 0x00, 0x3A}, 3}, //text55
  {{0x5F, 0x00, 0x3B}, 3}, //text56
  {{0x5F, 0x00, 0x3C}, 3}, //text57
  {{0x6F, 0x00, 0x01}, 3}, //text60
  {{0x6F, 0x00, 0x02}, 3}, //text61
  {{0x6F, 0x00, 0x03}, 3}, //text62
  {{0x6F, 0x00, 0x04}, 3}, //text63
  {{0x6F, 0x00, 0x05}, 3}, //text64
  {{0x6F, 0x00, 0x06}, 3}, //text65
  {{0x6F, 0x00, 0x07}, 3}, //text66
  {{0x7F, 0x00, 0x01}, 3}, //text67
  {{0x7F, 0x00, 0x02}, 3}, //text68
  {{0x7F, 0x00, 0x03}, 3}, //text69
  {{0x7F, 0x00, 0x04}, 3}, //text70
  {{0x7F, 0x00, 0x05}, 3}, //text71
  {{0x7F, 0x00, 0x06}, 3}, //text72
  {{0x7F, 0x00, 0x07}, 3}, //text73
   //已进入远红外线汗蒸模式，注意高温
  {{0x7F, 0x00, 0x08}, 3}, //text74
  {{0x7F, 0x00, 0x09}, 3}, //text75
  {{0x7F, 0x00, 0x10}, 3}, //text76
  {{0x7F, 0x00, 0x11}, 3}, //text77
  {{0x7F, 0x00, 0x12}, 3}, //text78
  //音量控制指令
  {{0x8F, 0x00, 0x11}, 3}, //text79
  {{0x8F, 0x00, 0x12}, 3}, //text80
  {{0x8F, 0x00, 0x13}, 3}, //text81
  {{0x8F, 0x00, 0x14}, 3}, //text82
  {{0x8F, 0x00, 0x15}, 3}, //text83

};

static void _custom_setting_cb(USER_EVENT_TYPE event,
                               user_event_context_t *context) {
  event_custom_setting_t *setting = NULL;
  if (context) {
    setting = &context->custom_setting;
    LOGT(TAG, "user command: %s", setting->cmd);
    if (0 == uni_strcmp(setting->cmd, "text1")) {
      user_uart_send(g_uart_buf[0].data, g_uart_buf[0].len);
    } else if (0 == uni_strcmp(setting->cmd, "text2")) {
      user_uart_send(g_uart_buf[1].data, g_uart_buf[1].len);
    } else if (0 == uni_strcmp(setting->cmd, "text3")) {
      user_uart_send(g_uart_buf[2].data, g_uart_buf[2].len);
    } else if (0 == uni_strcmp(setting->cmd, "text4")) {
      user_uart_send(g_uart_buf[3].data, g_uart_buf[3].len);
    } else if (0 == uni_strcmp(setting->cmd, "text5")) {
      user_uart_send(g_uart_buf[4].data, g_uart_buf[4].len);
    } else if (0 == uni_strcmp(setting->cmd, "text6")) {
      user_uart_send(g_uart_buf[5].data, g_uart_buf[5].len);
    } else if (0 == uni_strcmp(setting->cmd, "text7")) {
      user_uart_send(g_uart_buf[6].data, g_uart_buf[6].len);
    } else if (0 == uni_strcmp(setting->cmd, "text8")) {
      user_uart_send(g_uart_buf[7].data, g_uart_buf[7].len);
    } else if (0 == uni_strcmp(setting->cmd, "text9")) {
      user_uart_send(g_uart_buf[8].data, g_uart_buf[8].len);
    } else if (0 == uni_strcmp(setting->cmd, "text10")) {
      user_uart_send(g_uart_buf[9].data, g_uart_buf[9].len);
    } else if (0 == uni_strcmp(setting->cmd, "text11")) {
      user_uart_send(g_uart_buf[10].data, g_uart_buf[10].len);
    } else if (0 == uni_strcmp(setting->cmd, "text12")) {
      user_uart_send(g_uart_buf[11].data, g_uart_buf[11].len);
    } else if (0 == uni_strcmp(setting->cmd, "text13")) {
      user_uart_send(g_uart_buf[12].data, g_uart_buf[12].len);
    } else if (0 == uni_strcmp(setting->cmd, "text14")) {
      user_uart_send(g_uart_buf[13].data, g_uart_buf[13].len);
    } else if (0 == uni_strcmp(setting->cmd, "text15")) {
      user_uart_send(g_uart_buf[14].data, g_uart_buf[14].len);
    } else if (0 == uni_strcmp(setting->cmd, "text16")) {
      user_uart_send(g_uart_buf[15].data, g_uart_buf[15].len);
    } else if (0 == uni_strcmp(setting->cmd, "text17")) {
      user_uart_send(g_uart_buf[16].data, g_uart_buf[16].len);
    } else if (0 == uni_strcmp(setting->cmd, "text18")) {
      user_uart_send(g_uart_buf[17].data, g_uart_buf[17].len);
    } else if (0 == uni_strcmp(setting->cmd, "text19")) {
      user_uart_send(g_uart_buf[18].data, g_uart_buf[18].len);
    } else if (0 == uni_strcmp(setting->cmd, "text20")) {
      user_uart_send(g_uart_buf[19].data, g_uart_buf[19].len);
    } else if (0 == uni_strcmp(setting->cmd, "text21")) {
      user_uart_send(g_uart_buf[20].data, g_uart_buf[20].len);
    } else if (0 == uni_strcmp(setting->cmd, "text22")) {
      user_uart_send(g_uart_buf[21].data, g_uart_buf[21].len);
    } else if (0 == uni_strcmp(setting->cmd, "text23")) {
      user_uart_send(g_uart_buf[22].data, g_uart_buf[22].len);
    } else if (0 == uni_strcmp(setting->cmd, "text24")) {
      user_uart_send(g_uart_buf[23].data, g_uart_buf[23].len);
    } else if (0 == uni_strcmp(setting->cmd, "text25")) {
      user_uart_send(g_uart_buf[24].data, g_uart_buf[24].len);
    } else if (0 == uni_strcmp(setting->cmd, "text26")) {
      user_uart_send(g_uart_buf[25].data, g_uart_buf[25].len);
    } else if (0 == uni_strcmp(setting->cmd, "text27")) {
      user_uart_send(g_uart_buf[26].data, g_uart_buf[26].len);
    } else if (0 == uni_strcmp(setting->cmd, "text28")) {
      user_uart_send(g_uart_buf[27].data, g_uart_buf[27].len);
    } else if (0 == uni_strcmp(setting->cmd, "text29")) {
      user_uart_send(g_uart_buf[28].data, g_uart_buf[28].len);
    } else if (0 == uni_strcmp(setting->cmd, "text30")) {
      user_uart_send(g_uart_buf[29].data, g_uart_buf[29].len);
    } else if (0 == uni_strcmp(setting->cmd, "text31")) {
      user_uart_send(g_uart_buf[30].data, g_uart_buf[30].len);
    } else if (0 == uni_strcmp(setting->cmd, "text32")) {
      user_uart_send(g_uart_buf[31].data, g_uart_buf[31].len);
    } else if (0 == uni_strcmp(setting->cmd, "text33")) {
      user_uart_send(g_uart_buf[32].data, g_uart_buf[32].len);
    } else if (0 == uni_strcmp(setting->cmd, "text34")) {
      user_uart_send(g_uart_buf[33].data, g_uart_buf[33].len);
    } else if (0 == uni_strcmp(setting->cmd, "text35")) {
      user_uart_send(g_uart_buf[34].data, g_uart_buf[34].len);
    } else if (0 == uni_strcmp(setting->cmd, "text36")) {
      user_uart_send(g_uart_buf[35].data, g_uart_buf[35].len);
    } else if (0 == uni_strcmp(setting->cmd, "text37")) {
      user_uart_send(g_uart_buf[36].data, g_uart_buf[36].len);
    } else if (0 == uni_strcmp(setting->cmd, "text38")) {
      user_uart_send(g_uart_buf[37].data, g_uart_buf[37].len);
    } else if (0 == uni_strcmp(setting->cmd, "text39")) {
      user_uart_send(g_uart_buf[38].data, g_uart_buf[38].len);
    } else if (0 == uni_strcmp(setting->cmd, "text40")) {
      user_uart_send(g_uart_buf[39].data, g_uart_buf[39].len);
    } else if (0 == uni_strcmp(setting->cmd, "text41")) {
      user_uart_send(g_uart_buf[40].data, g_uart_buf[40].len);
    } else if (0 == uni_strcmp(setting->cmd, "text42")) {
      user_uart_send(g_uart_buf[41].data, g_uart_buf[41].len);
    } else if (0 == uni_strcmp(setting->cmd, "text43")) {
      user_uart_send(g_uart_buf[42].data, g_uart_buf[42].len);
    } else if (0 == uni_strcmp(setting->cmd, "text44")) {
      user_uart_send(g_uart_buf[43].data, g_uart_buf[43].len);
    } else if (0 == uni_strcmp(setting->cmd, "text45")) {
      user_uart_send(g_uart_buf[44].data, g_uart_buf[44].len);
    } else if (0 == uni_strcmp(setting->cmd, "text46")) {
      user_uart_send(g_uart_buf[45].data, g_uart_buf[45].len);
    } else if (0 == uni_strcmp(setting->cmd, "text47")) {
      user_uart_send(g_uart_buf[46].data, g_uart_buf[46].len);
    } else if (0 == uni_strcmp(setting->cmd, "text48")) {
      user_uart_send(g_uart_buf[47].data, g_uart_buf[47].len);
    } else if (0 == uni_strcmp(setting->cmd, "text49")) {
      user_uart_send(g_uart_buf[48].data, g_uart_buf[48].len);
    } else if (0 == uni_strcmp(setting->cmd, "text50")) {
      user_uart_send(g_uart_buf[49].data, g_uart_buf[49].len);
    } else if (0 == uni_strcmp(setting->cmd, "text51")) {
      user_uart_send(g_uart_buf[50].data, g_uart_buf[50].len);
    } else if (0 == uni_strcmp(setting->cmd, "text52")) {
      user_uart_send(g_uart_buf[51].data, g_uart_buf[51].len);
    } else if (0 == uni_strcmp(setting->cmd, "text53")) {
      user_uart_send(g_uart_buf[52].data, g_uart_buf[52].len);
    } else if (0 == uni_strcmp(setting->cmd, "text54")) {
      user_uart_send(g_uart_buf[53].data, g_uart_buf[53].len);
    } else if (0 == uni_strcmp(setting->cmd, "text55")) {
      user_uart_send(g_uart_buf[54].data, g_uart_buf[54].len);
    } else if (0 == uni_strcmp(setting->cmd, "text56")) {
      user_uart_send(g_uart_buf[55].data, g_uart_buf[55].len);
    } else if (0 == uni_strcmp(setting->cmd, "text57")) {
      user_uart_send(g_uart_buf[56].data, g_uart_buf[56].len);
    } else if (0 == uni_strcmp(setting->cmd, "text60")) {
      user_uart_send(g_uart_buf[57].data, g_uart_buf[57].len);
    } else if (0 == uni_strcmp(setting->cmd, "text61")) {
      user_uart_send(g_uart_buf[58].data, g_uart_buf[58].len);
    } else if (0 == uni_strcmp(setting->cmd, "text62")) {
      user_uart_send(g_uart_buf[59].data, g_uart_buf[59].len);
    } else if (0 == uni_strcmp(setting->cmd, "text63")) {
      user_uart_send(g_uart_buf[60].data, g_uart_buf[60].len);
    } else if (0 == uni_strcmp(setting->cmd, "text64")) {
      user_uart_send(g_uart_buf[61].data, g_uart_buf[61].len);
    } else if (0 == uni_strcmp(setting->cmd, "text65")) {
      user_uart_send(g_uart_buf[62].data, g_uart_buf[62].len);
    } else if (0 == uni_strcmp(setting->cmd, "text66")) {
      user_uart_send(g_uart_buf[63].data, g_uart_buf[63].len);
    } else if (0 == uni_strcmp(setting->cmd, "text67")) {
      user_uart_send(g_uart_buf[64].data, g_uart_buf[64].len);
    } else if (0 == uni_strcmp(setting->cmd, "text68")) {
      user_uart_send(g_uart_buf[65].data, g_uart_buf[65].len);
    } else if (0 == uni_strcmp(setting->cmd, "text69")) {
      user_uart_send(g_uart_buf[66].data, g_uart_buf[66].len);
    } else if (0 == uni_strcmp(setting->cmd, "text70")) {
      user_uart_send(g_uart_buf[67].data, g_uart_buf[67].len);
    } else if (0 == uni_strcmp(setting->cmd, "text71")) {
      user_uart_send(g_uart_buf[68].data, g_uart_buf[68].len); 
    }else if (0 == uni_strcmp(setting->cmd, "text72")) {
      user_uart_send(g_uart_buf[69].data, g_uart_buf[69].len); 
    }else if (0 == uni_strcmp(setting->cmd, "text73")) {
      user_uart_send(g_uart_buf[70].data, g_uart_buf[70].len); 
    }else if (0 == uni_strcmp(setting->cmd, "text74")) {
      user_uart_send(g_uart_buf[71].data, g_uart_buf[71].len); 
    }else {
      LOGT(TAG, "Unconcerned command: %s", setting->cmd);
    }
    user_player_reply_list_random(setting->reply_files);
  }
}


/*增加串口输入控制*/
static int buf_len=0;   //接收且判断协议正误
static uint8_t pack_buf[255];
static void hlk_hb_uart_recv(char *buf, int len) 
{
  printf("len = %d: ",len);
  int i;
  for (i = 0; i < len; i++) 
  {
    printf("%02x ", (uint8_t)buf[i]);
  }
  printf("\n");

  uni_memcpy(pack_buf+buf_len,buf,len);
  buf_len+=len;
  printf("buf_len = %d: ",buf_len);
  for (i = 0; i < buf_len; i++) 
  {
    printf("%02x ", (uint8_t)pack_buf[i]);
  }
  printf("\n");

  if(buf_len >= 1)
  {
    if((uint8_t)pack_buf[1] != 0x00)
    {
      buf_len=0;
      memset(pack_buf,0,sizeof(pack_buf));
    }
  }

  if(buf_len == 3)     // 根据协议去播报语音
  {  
    if((uint8_t)pack_buf[1] == 0x00)
    {    //好的音效
      if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x05 )
      {
        user_player_reply_list_random("[500]");    
      }
      //开机音效
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x06 )
      {
        user_player_reply_list_random("[502]");    
      }
      //按键音效
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x07 )
      {
        user_player_reply_list_random("[501]");    
      }
      //已启动睡眠1小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x01 )
      {
        user_player_reply_list_random("[503]");    
      }
      //已启动睡眠两小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x02 )
      {
        user_player_reply_list_random("[504]");    
      }
      //已启动睡眠三小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x03 )
      {
        user_player_reply_list_random("[505]");    
      }
      //已启动睡眠四小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x04 )
      {
        user_player_reply_list_random("[506]");    
      }
      //已启动睡眠五小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x05 )
      {
        user_player_reply_list_random("[507]");   
      }
      //已启动睡眠六小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x06 )
      {
        user_player_reply_list_random("[508]");    
      }
      //已启动睡眠七小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x07 )
      {
        user_player_reply_list_random("[509]");    
      }
      //已启动睡眠八小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x08 )
      {
        user_player_reply_list_random("[510]");    
      }
      //已启动睡眠九小时
      else if((uint8_t)pack_buf[0] == 0x4F && (uint8_t)pack_buf[2] ==0x09 )
      {
        user_player_reply_list_random("[511]");    
      }
      //已进入远红外线汗蒸模式，注意高温
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x08 )
      {
        user_player_reply_list_random("[512]");    
      }
      //已进入汗蒸模式，注意高温
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x09 )
      {
        user_player_reply_list_random("[513]");    
      }
      //已进入高温模式
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x10 )
      {
        user_player_reply_list_random("[514]");    
      }
      //睡眠模式下，温度范围25度到35度
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x11 )
      {
        user_player_reply_list_random("[515]");    
      }
      //已超出睡眠模式温度范围，请重新设定
      else if((uint8_t)pack_buf[0] == 0x7F && (uint8_t)pack_buf[2] ==0x12 )
      {
        user_player_reply_list_random("[516]");    
      }
      //调整音量，增大音量
      else if((uint8_t)pack_buf[0] == 0x8F && (uint8_t)pack_buf[2] ==0x11)
      {
        user_player_set_volume_up();
        user_uart_send(g_uart_buf[72].data, g_uart_buf[71].len);

      }
      //调整音量，最大音量
      else if((uint8_t)pack_buf[0] == 0x8F && (uint8_t)pack_buf[2] ==0x12)
      {
        user_player_set_volume_max();
        user_uart_send(g_uart_buf[73].data, g_uart_buf[71].len);

      }

      //调整音量，中等音量
      else if((uint8_t)pack_buf[0] == 0x8F && (uint8_t)pack_buf[2] ==0x13)
      {
        user_player_set_volume_mid();
        user_uart_send(g_uart_buf[74].data, g_uart_buf[71].len);

      }
      //调整音量，减小音量
      else if((uint8_t)pack_buf[0] == 0x8F && (uint8_t)pack_buf[2] ==0x14)
      {
        user_player_set_volume_down();
        user_uart_send(g_uart_buf[75].data, g_uart_buf[71].len);

      }
     //调整音量，最小音量
      else if((uint8_t)pack_buf[0] == 0x8F && (uint8_t)pack_buf[2] ==0x15)
      {
        user_player_set_volume_min();
        user_uart_send(g_uart_buf[76].data, g_uart_buf[71].len);

      }

    }
    buf_len=0;
    memset(pack_buf,0,sizeof(pack_buf));
  }
  else if(buf_len > 3)
  {
    buf_len=0;
    memset(pack_buf,0,sizeof(pack_buf));
  }
} 

static void _register_event_callback(void) {
  user_event_subscribe_event(USER_CUSTOM_SETTING, _custom_setting_cb);
}

int hb_auto_gpio(void) {
  user_gpio_init();
  user_gpio_set_mode(GPIO_NUM_A25, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_A25, 0);
  user_gpio_set_mode(GPIO_NUM_A26, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_A26, 0);
  user_gpio_set_mode(GPIO_NUM_A27, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_A27, 0);
  user_gpio_set_mode(GPIO_NUM_A28, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_A28, 0);
  user_gpio_set_mode(GPIO_NUM_B6, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_B6, 0);
  user_gpio_set_mode(GPIO_NUM_B7, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_B7, 0);
  user_gpio_set_mode(GPIO_NUM_B2, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_B2, 0);
  user_gpio_set_mode(GPIO_NUM_B3, GPIO_MODE_OUT);
  user_gpio_set_value(GPIO_NUM_B3, 0);
int ret = user_uart_init(hlk_hb_uart_recv);
  if (ret != 0) {
    LOGE(TAG, "hb uart init failed");
    return -1;
  }
  _register_event_callback();
  return 0;
}

